package main

import (
	"fmt"
	"google.golang.org/protobuf/proto"
	"protobufDemo/pb"
)

func main() {
	person := &pb.Person{
		Name:   "delong",
		Age:    33,
		Emails: []string{"111@163.com", "222@qq.com"},
		Phones: []*pb.PhoneNumber{
			&pb.PhoneNumber{
				Number: "111111",
				Type:   pb.PhoneType_HOME,
			},
			&pb.PhoneNumber{
				Number: "2222",
				Type:   pb.PhoneType_MOBILE,
			},
			&pb.PhoneNumber{
				Number: "3333",
				Type:   pb.PhoneType_WORK,
			},
		},
	}

	// 打包
	data, err := proto.Marshal(person)
	if err != nil {
		fmt.Println("person marshal error: ", err)
		return
	}

	// 解压
	newPerson := &pb.Person{}
	err = proto.Unmarshal(data, newPerson)
	if err != nil {
		fmt.Println("person unmarshal error: ", err)
		return
	}

	fmt.Println(person)

	fmt.Println(newPerson)
}
